<template>
<div class="user clearfix">
    <!--提现管理-->
    <div class="common-seach-wrap fr">
      <el-form
        size="small"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item :label="$t('supplier.merchant_name')">
          <el-input
            v-model="formInline.search"
            :placeholder="$t('supplier.input_merchant_name')"
          ></el-input>
        </el-form-item>
        <el-form-item :label="$t('supplier.review_status')">
          <el-select v-model="formInline.applyStatus" :placeholder="$t('supplier.please_select_status')">
            <el-option :label="$t('supplier.all')" value="-1"></el-option>
            <el-option :label="$t('supplier.pending_review')" value="10"></el-option>
            <el-option :label="$t('supplier.approved')" value="20"></el-option>
            <el-option :label="$t('supplier.paid')" value="40"></el-option>
            <el-option :label="$t('supplier.rejected')" value="30"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('supplier.withdraw_method')">
          <el-select v-model="formInline.payType" :placeholder="$t('supplier.please_select_method')">
            <el-option :label="$t('supplier.all')" value="-1"></el-option>
            <el-option :label="$t('supplier.alipay')" value="10"></el-option>
            <el-option :label="$t('supplier.bank_card')" value="20"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="Search" @click="onSubmit"
            >{{$t('supplier.search')}}</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <!--内容-->
    <div class="product-content">
      <div class="table-wrap">
        <el-table
          size="small"
          :data="tableData"
          border
          style="width: 100%"
          v-loading="loading"
        >
          <el-table-column prop="supplierName" :label="$t('supplier.merchant')">
            <template #default="scope">
              <span v-if="scope.row.shopSupplierId">{{scope.row.supplierName}}

</span>
            </template>
          </el-table-column>
          <el-table-column prop="money" :label="$t('supplier.withdraw_amount')">
            <template #default="scope">
              <span class="fb orange">{{scope.row.money}}</span>
            </template>
          </el-table-column>
          <el-table-column :label="$t('supplier.payment_method')">
            <template #default="scope">
              {{scope.row.payTypeText}}
            </template>
          </el-table-column>
          <el-table-column :label="$t('supplier.payment_info')" show-overflow-tooltip>
            <template #default="scope">
              <span v-if="scope.row.payType == 10"> {{$t('supplier.info_name',{place1:scope.row.alipayName})}}
<br /> {{$t('supplier.info_account',{place1:scope.row.alipayAccount})}}
</span
              >
              <span v-if="scope.row.payType == 20"> {{$t('supplier.info_name',{place1:scope.row.bankAccount})}}
<br /> {{$t('supplier.info_bank',{place1:scope.row.bankName})}}
<br /> {{$t('supplier.info_account',{place1:scope.row.bankCard})}}

              </span>
            </template>
          </el-table-column>
          <el-table-column prop="applyStatus" :label="$t('supplier.status')">
            <template #default="scope">
              <span v-if="scope.row.applyStatus == 10">{{$t('supplier.pending_review')}}</span>
              <span v-if="scope.row.applyStatus == 20">{{$t('supplier.approved')}}</span>
              <div v-if="scope.row.applyStatus == 30"> {{$t('supplier.rejected')}} 
<span class="red">{{$t('supplier.reject_reason',{place1:scope.row.rejectReason})}}</span>
              </div>
              <span v-if="scope.row.applyStatus == 40">{{$t('supplier.paid')}}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="createTime"
            :label="$t('supplier.added_time')"
            width="150"
          ></el-table-column>
          <el-table-column fixed="right" :label="$t('supplier.actions')" width="90">
            <template #default="scope">
              <template v-if="scope.row.applyStatus == 10">
                <el-button
                  @click="submitClick(scope.row)"
                  type="text"
                  size="small"
                  >{{$t('supplier.review')}}</el-button
                >
              </template>
              <template
                v-if="scope.row.applyStatus == 20 && scope.row.payType == 20"
              >
                <el-button
                  @click="makeMoney(scope.row)"
                  type="text"
                  size="small"
                  >{{$t('supplier.confirm_payment')}}</el-button
                >
              </template>
              <template
                v-if="scope.row.applyStatus == 20 && scope.row.payType == 10"
              >
                <el-button @click="aliPay(scope.row)" type="text" size="small"
                  >{{$t('supplier.alipay_payment')}}</el-button
                >
              </template>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!--分页-->
      <div class="pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
          :current-page="curPage"
          :page-size="pageSize"
          layout="total, prev, pager, next, jumper"
          :total="totalDataNumber"
        >
        </el-pagination>
      </div>
    </div>

    <!--审核-->
    <Submit :open="open_submit" :form="curModel" @close="closeSubmit"></Submit>
  </div>
</template>

<script>
import SupplierApi from "@/api/supplier.js";
import Submit from "./dialog/Submit.vue";
import { deepClone } from "@/utils/base";
export default {
  components: {
    Submit
  },
  data() {
    return {
      /*是否加载完成*/
      loading: true,
      /*列表数据*/
      tableData: [],
      /*门店列表数据*/
      storeList: [],
      /*一页多少条*/
      pageSize: 15,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      /*横向表单数据模型*/
      formInline: {
        search: "",
        applyStatus: "-1",
        payType: "-1"
      },
      /*是否打开添加弹窗*/
      open_add: false,
      /*是否打开编辑弹窗*/
      open_edit: false,
      /*当前编辑的对象*/
      curModel: {},
      /*是否打开审核 */
      open_submit: false
    };
  },
  created() {
    /*获取列表*/
    this.getTableList();
  },
  methods: {
    /*选择第几页*/
    handleCurrentChange(val) {
      let self = this;
      self.curPage = val;
      self.loading = true;
      self.getTableList();
    },
    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getTableList();
    },
    /*获取列表*/
    getTableList() {
      let self = this;
      let Params = self.formInline;
      Params.pageIndex = self.curPage;
      Params.pageSize = self.pageSize;
      SupplierApi.cashList(Params, true).then(res => {
        self.loading = false;
        self.tableData = res.data.records;
        self.totalDataNumber = res.data.total;
      }).catch(error => {
        self.loading = false;
      });
    },
    /*搜索查询*/
    onSubmit() {
      this.curPage = 1;
      this.getTableList();
    },
    /*审核*/
    submitClick(row) {
      this.curModel = deepClone(row);
      this.open_submit = true;
    },
    /*关闭审核*/
    closeSubmit(e) {
      this.open_submit = false;
      if (e) {
        this.getTableList();
      }
    },
    /*支付宝打款*/
    aliPay(e) {
      let self = this;
      ElMessageBox.confirm($t("supplier.confirm_alipay_payment_prompti0"), $t("supplier.alert"), {
        confirmButtonText: $t("supplier.confirm"),
        cancelButtonText: $t("supplier.cancel"),
        type: "warning"
      }).then(() => {
        self.loading = true;
        SupplierApi.aliPay({
          id: e.id
        }, true).then(data => {
          self.loading = false;
          if (data.code == 1) {
            ElMessage({
              message: $t("supplier.operation_success"),
              type: "success"
            });
            this.getData();
          } else {
            self.loading = false;
          }
        }).catch(error => {
          self.loading = false;
        });
      }).catch(() => {});
    },
    /*确认打款*/
    makeMoney(e) {
      let self = this;
      ElMessageBox.confirm($t("supplier.confirm_payment_prompt"), $t("supplier.alert"), {
        confirmButtonText: $t("supplier.confirm"),
        cancelButtonText: $t("supplier.cancel"),
        type: "warning"
      }).then(() => {
        self.loading = true;
        SupplierApi.cashMoney({
          id: e.id
        }, true).then(data => {
          self.loading = false;
          if (data.code == 1) {
            ElMessage({
              message: $t("supplier.operation_success"),
              type: "success"
            });
            this.getTableList();
          } else {
            self.loading = false;
          }
        }).catch(error => {
          self.loading = false;
        });
      }).catch(() => {});
    }
  }
};
</script>

